<?php
class Users extends Front_Controller
{
	public function __construct()
	{
		parent::__construct();
		$this->load->model('users/users_model','users');
		$this->load->model('country/country_model','country');
		$this->load->model('province/province_model','province');
		
	}
	
	public function check_email_exist()
	{
		$email = $this->db->getone("SELECT email FROM users WHERE email='".trim(@$_GET['email'])."'");
		if($email==''){
			echo 'true';
		}else{echo 'false';}
		
	}
	public function complete($lang=FALSE)
	{
		$lang = $lang == FALSE ? 'th' : $lang;
		$data['lang'] = $lang;
		$data['register_complete'] = $lang=='th' ? 'สมัครสมาชิกเสร็จเรียบร้อย  ขณะนี้ท่านสามารถใช้ อีเมล์ และ รหัสผ่านนี้ ทำการล้อกอินและเลือกซื้อค้าจากทางเว็บไซต์ของเราได้ทันทีค่ะ' : 'register complete now you can log in website with your register email and password for shopping our products. thank you.';
		$this->template->build('complete',$data);
	}
	public function save(){
		//$this->db->debug = true;
		$_POST['password'] =  $_POST['id']!='' && $_POST['password']=='' ? $_POST['current_password'] : $_POST['password'];
		$_POST['registerdate'] =  $_POST['id']!='' && $_POST['password']=='' ? $_POST['registerdate'] : date("Y-m-d H:i:s");
		$id = $this->users->save($_POST);
		$user = $this->users->get_row($id);		
		//set_notify('success', lang('save_data_complete'));
		SendUserEmail($user);
		redirect('register/complete');
	} 
}
?>